//
//  SPBOrderDelegate.m
//  FLMSuperS
//
//  Created by yakun yin on 2016/10/13.
//  Copyright © 2016年 FaLaoMiaoNetworkTechnologyCo. All rights reserved.
//

#import "SPBOrderDelegate.h"
#import "XLsn0wNetwork.h"
#import "FLMOrderModel.h"
@interface SPBOrderDelegate ()
{
    orderType orderT;
}
@end

@implementation SPBOrderDelegate
- (void)datasWithRequestType:(orderType)currentOrderType WithBlock:(callBackData)cb{
    orderT = currentOrderType;
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    NSString *reqURL;
    if (currentOrderType == orderTypeWaitCheck) {   //等待审核单
        reqURL = ExamineOrderURL;
        parameters[@"uname"] = @"13411932317";
        parameters[@"upass"] = [BaseHttpRequest md5HexDigest:[NSString stringWithFormat:@"%@%@",@"123456",@"sos_5941m"]];
        parameters[@"code"] = @"";
        parameters[@"token"] = @"f2c8ec76b30527be791752cab0cf743c";
        parameters[@"h"] = @"141";
        parameters[@"id"] = @"27";
    }
    else if (currentOrderType == orderTypeTao){     //淘宝订单
        reqURL = TaoBaoOrderURL;
        parameters[@"uname"] = @"13411932317";
        parameters[@"upass"] = [BaseHttpRequest md5HexDigest:[NSString stringWithFormat:@"%@%@",@"123456",@"sos_5941m"]];
        parameters[@"code"] = @"";
        parameters[@"token"] = @"f2c8ec76b30527be791752cab0cf743c";
        parameters[@"h"] = @"141";
        parameters[@"id"] = @"27";
    }
    else if (currentOrderType == orderTypeMarket){  //商城订单
        reqURL = ShopOrderURL;
        parameters[@"uname"] = @"13411932317";
        parameters[@"upass"] = [BaseHttpRequest md5HexDigest:[NSString stringWithFormat:@"%@%@",@"123456",@"sos_5941m"]];
        parameters[@"code"] = @"";
        parameters[@"token"] = @"f2c8ec76b30527be791752cab0cf743c";
        parameters[@"h"] = @"141";
        parameters[@"id"] = @"27";
    }
    
    [[XLsn0wNetwork defaultNetwork] POST:reqURL token:nil params:parameters success:^(NSURLSessionDataTask *task, NSDictionary *JSONDictionary, NSString *JSONString) {
        if ([JSONDictionary[@"succ"]intValue]){
            NSMutableArray *OrderslistArray = [NSMutableArray array];
            //这一个 if else  有正式数据了删除.
            if (currentOrderType == orderTypeTao) {
                JSONDictionary = @{ @"msg" :@{@"Orderslist" :
                                                  @[
                                                      @{
                                                          @"buynum" : @(2).description,
                                                          @"id" : @(99).description,
                                                          @"order_id" : @(20821939426),
                                                          @"pay" : @"59.0",
                                                          @"porder_time" : @(0).description ,
                                                          @"status" : @(3).description,
                                                          @"super_money" : @(64).description,
                                                          @"title" : @"康佳电风扇台式风扇落地扇摇头家用静音鸿运扇转页扇学生宿舍风扇",
                                                          @"super_money" : @"44",
                                                          @"click_url" : @"null",
                                                          @"type" : @(1).description,
                                                          @"pict_url" : @"",
                                                          @"g_id":@"529361265244"
                                                          },
                                                      @{
                                                          @"buynum" : @(2).description,
                                                          @"id" : @(99).description,
                                                          @"order_id" : @(20821939426),
                                                          @"pay" : @"59.0",
                                                          @"porder_time" : @(0).description ,
                                                          @"status" : @(3).description,
                                                          @"super_money" : @(64).description,
                                                          @"title" : @"康佳电风扇台式风扇落地扇摇头家用静音鸿运扇转页扇学生宿舍风扇",
                                                          @"super_money" : @"44",
                                                          @"click_url" : @"null",
                                                          @"type" : @(1).description,
                                                          @"pict_url" : @"",
                                                          @"g_id":@"529361265244"
                                                          },
                                                      @{
                                                          @"buynum" : @(2).description,
                                                          @"id" : @(99).description,
                                                          @"order_id" : @(20821939426),
                                                          @"pay" : @"59.0",
                                                          @"porder_time" : @(0).description ,
                                                          @"status" : @(3).description,
                                                          @"super_money" : @(64).description,
                                                          @"title" : @"康佳电风扇台式风扇落地扇摇头家用静音鸿运扇转页扇学生宿舍风扇",
                                                          @"super_money" : @"44",
                                                          @"click_url" : @"null",
                                                          @"type" : @(1).description,
                                                          @"pict_url" : @"",
                                                          @"g_id":@"529361265244"
                                                          }
                                                      ]
                                              },
                                    @"succ" : [NSNumber numberWithInt:1],
                                    };
                
                
   
            }
            else if (currentOrderType == orderTypeMarket){
                JSONDictionary = @{ @"msg" :@{@"Orderslist" :
                                                  @[
                                                      @{
                                                          @"buynum" : @(2).description,
                                                          @"id" : @(99).description,
                                                          @"order_id" : @(20821939426),
                                                          @"pay" : @"<null>",
                                                          @"porder_time" : @(0).description ,
                                                          @"status" : @(2).description,
                                                          @"super_money" : @(440).description,
                                                          }
                                                      ]
                                              },
                                    @"succ" : [NSNumber numberWithInt:1],
                                    };
                

            }
            else{
                JSONDictionary = @{ @"msg" :@{@"Orderslist" :
                                                  @[
                                                      @{
                                                          @"buynum" : @(2).description,
                                                          @"id" : @(99).description,
                                                          @"order_id" : @(20821939426),
                                                          @"pay" : @"<null>",
                                                          @"porder_time" : @(0).description ,
                                                          @"status" : @(2).description,
                                                          @"super_money" : @(440).description,
                                                          @"title" : @"日本进口Calbee卡乐比水果谷物即食早餐冲饮燕麦片800g卡乐B包邮",
                                                          @"super_money" : @"44",
                                                          @"click_url" : @"null",
                                                          @"type" : @(1).description,
                                                          @"pict_url" : @"",
                                                          }
                                                      ]
                                              },
                                    @"succ" : [NSNumber numberWithInt:1],
                                    };

            }
            
            NSArray *array = JSONDictionary[@"msg"][@"Orderslist"];
            for (NSDictionary *dic in array)
            {
                FLMOrderModel *model = [[FLMOrderModel alloc]init];
                [model setValuesForKeysWithDictionary:dic];
                [OrderslistArray addObject:model];
            }
            cb(YES,OrderslistArray);
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error, NSInteger statusCode, NSString *requestFailedReason) {
        cb(NO,nil);
    }];
}


- (void)datasWithRequestType:(orderType)currentOrderType pages:(NSInteger )pages WithBlock:(callBackData)cb
{
    
    orderT = currentOrderType;
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    NSString *reqURL;
    parameters[@"uname"] = @"13411932317";
    parameters[@"upass"] = [BaseHttpRequest md5HexDigest:[NSString stringWithFormat:@"%@%@",@"123456",@"sos_5941m"]];
    parameters[@"code"] = @"";
    parameters[@"token"] = @"f2c8ec76b30527be791752cab0cf743c";
    parameters[@"h"] = @"141";
    parameters[@"id"] = @"27";
    parameters[@"page"] = [NSNumber numberWithInteger:pages];

    if (currentOrderType == orderTypeWaitCheck) {   //等待审核单
        reqURL = ExamineOrderURL;
        parameters[@"type"] = [NSNumber numberWithInteger:3];
    }
    else if (currentOrderType == orderTypeTao){     //淘宝订单
        reqURL = TaoBaoOrderURL;
        parameters[@"type"] = [NSNumber numberWithInteger:1];

    }
    else if (currentOrderType == orderTypeMarket){  //商城订单
        reqURL = ShopOrderURL;
        parameters[@"type"] = [NSNumber numberWithInteger:2];
    }
    
    
    [[XLsn0wNetwork defaultNetwork] POST:ShopOrderLoadMoreURL token:nil params:parameters success:^(NSURLSessionDataTask *task, NSDictionary *JSONDictionary, NSString *JSONString) {
        if ([JSONDictionary[@"succ"]intValue]){
            NSMutableArray *OrderslistArray = [NSMutableArray array];
            
            if (currentOrderType == orderTypeTao) {
                JSONDictionary = @{ @"msg" :@{@"Orderslist" :
                                                  @[
                                                      @{
                                                          @"buynum" : @(2).description,
                                                          @"id" : @(99).description,
                                                          @"order_id" : @(20821939426),
                                                          @"pay" : @"59.0",
                                                          @"porder_time" : @(0).description ,
                                                          @"status" : @(3).description,
                                                          @"super_money" : @(64).description,
                                                          @"title" : @"康佳电风扇台式风扇落地扇摇头家用静音鸿运扇转页扇学生宿舍风扇",
                                                          @"super_money" : @"44",
                                                          @"click_url" : @"null",
                                                          @"type" : @(1).description,
                                                          @"pict_url" : @"",
                                                          @"g_id":@"529361265244"
                                                          },
                                                      @{
                                                          @"buynum" : @(2).description,
                                                          @"id" : @(99).description,
                                                          @"order_id" : @(20821939426),
                                                          @"pay" : @"59.0",
                                                          @"porder_time" : @(0).description ,
                                                          @"status" : @(3).description,
                                                          @"super_money" : @(64).description,
                                                          @"title" : @"康佳电风扇台式风扇落地扇摇头家用静音鸿运扇转页扇学生宿舍风扇",
                                                          @"super_money" : @"44",
                                                          @"click_url" : @"null",
                                                          @"type" : @(1).description,
                                                          @"pict_url" : @"",
                                                          @"g_id":@"529361265244"
                                                          },
                                                      @{
                                                          @"buynum" : @(2).description,
                                                          @"id" : @(99).description,
                                                          @"order_id" : @(20821939426),
                                                          @"pay" : @"59.0",
                                                          @"porder_time" : @(0).description ,
                                                          @"status" : @(3).description,
                                                          @"super_money" : @(64).description,
                                                          @"title" : @"康佳电风扇台式风扇落地扇摇头家用静音鸿运扇转页扇学生宿舍风扇",
                                                          @"super_money" : @"44",
                                                          @"click_url" : @"null",
                                                          @"type" : @(1).description,
                                                          @"pict_url" : @"",
                                                          @"g_id":@"529361265244"
                                                          }
                                                      ]
                                              },
                                    @"succ" : [NSNumber numberWithInt:1],
                                    };
                
                
                
            }
            else if (currentOrderType == orderTypeMarket){
                JSONDictionary = @{ @"msg" :@{@"Orderslist" :
                                                  @[
                                                      @{
                                                          @"buynum" : @(2).description,
                                                          @"id" : @(99).description,
                                                          @"order_id" : @(20821939426),
                                                          @"pay" : @"<null>",
                                                          @"porder_time" : @(0).description ,
                                                          @"status" : @(2).description,
                                                          @"super_money" : @(440).description,
                                                          }
                                                      ]
                                              },
                                    @"succ" : [NSNumber numberWithInt:1],
                                    };
                
                
            }
            else{
                JSONDictionary = @{ @"msg" :@{@"Orderslist" :
                                                  @[
                                                      @{
                                                          @"buynum" : @(2).description,
                                                          @"id" : @(99).description,
                                                          @"order_id" : @(20821939426),
                                                          @"pay" : @"<null>",
                                                          @"porder_time" : @(0).description ,
                                                          @"status" : @(2).description,
                                                          @"super_money" : @(440).description,
                                                          @"title" : @"日本进口Calbee卡乐比水果谷物即食早餐冲饮燕麦片800g卡乐B包邮",
                                                          @"super_money" : @"44",
                                                          @"click_url" : @"null",
                                                          @"type" : @(1).description,
                                                          @"pict_url" : @"",
                                                          }
                                                      ]
                                              },
                                    @"succ" : [NSNumber numberWithInt:1],
                                    };
                
            }
            
            NSArray *array = JSONDictionary[@"msg"][@"Orderslist"];
            for (NSDictionary *dic in array)
            {
                FLMOrderModel *model = [[FLMOrderModel alloc]init];
                [model setValuesForKeysWithDictionary:dic];
                [OrderslistArray addObject:model];
            }
            cb(YES,OrderslistArray);
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error, NSInteger statusCode, NSString *requestFailedReason) {
        cb(NO,nil);
    }];

}
@end
